﻿using AutoMapper;
using MediatR;
using WeekWork929.Api.Write.Appliaction.Commond;
using WeekWork929.Domain;
using WeekWork929.ErrorCode;
using WeekWork929.infrastrunceture;

namespace WeekWork929.Api.Write.Appliaction.CommondHandler
{
    public class MasenAddCommondHandler : IRequestHandler<MasenAddCommond, ApiResult<int>>
    {
        private readonly IBaseIRepository<Masenmdooe> masenmd;
        private readonly IMapper mapper;

        public MasenAddCommondHandler(IBaseIRepository<Masenmdooe> masenmd, IMapper mapper)
        {
            this.masenmd = masenmd;
            this.mapper = mapper;
        }

        public async Task<ApiResult<int>> Handle(MasenAddCommond request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            result.Code=ApiEnum.增加成功;
            result.Msg=ApiEnum.增加成功.ToString();
            Masenmdooe masenmdooe = mapper.Map<Masenmdooe>(request);
            await masenmd.Add(masenmdooe);
            return await Task.FromResult(result);
        }
    }
}
